package org.yxt.message.push.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/***
 *
 *Knife4j是Swagger升级版
 *
 *@author YangXiuteng
 *@date 2020/2/25
 **/
@Configuration
@EnableSwagger2
@EnableKnife4j
@Import(BeanValidatorPluginsConfiguration.class)
public class Swagger2Config {

    /**
     * 注解为bean
     *
     * @return
     */
    @Bean
    public Docket buildDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(buildApiInf())
                .select()
                .build()
                .groupName("信息发布平台")
                .select()
                //这里指定Controller扫描包路径(项目路径也行) 如果启用扫描器加载则不需要
                .apis(RequestHandlerSelectors.basePackage("org.yxt.message.push.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo buildApiInf() {
        ApiInfoBuilder apiInfoBuilder = new ApiInfoBuilder()
                .title("信息发布平台api")
                // 服务说明url
                .termsOfServiceUrl("http://www.yxt.org")
                .description("消息推送服务")
                .version("v1.0")
                // 授权方式
                .license("MIT")
                // 授权连接
                .licenseUrl("https://yxt.org/")
                .contact(new Contact("杨秀腾", "https://localhost:8080/message-push/doc.html", "1047543512@qq.com"));
        return apiInfoBuilder.build();
    }


}
